<!DOCTYPE html>
<html lang="zh-CN">
	<head>
		<meta charset="UTF-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<title>事件委托</title>
		<style>
			.grandparent {
				width: 300px;
				height: 300px;
				background-color: pink;
			}
			.parent {
				width: 200px;
				height: 200px;
				background-color: skyblue;
				margin: 30px;
			}
			.child {
				width: 100px;
				height: 100px;
				background-color: purple;
				margin: 30px;
			}
		</style>
	</head>
	<body>
		<div class="grandparent">
			Grandparent
			<div class="parent">
				Parent
				<div class="child">Child</div>
			</div>
		</div>

		<script>
			const grandparent = document.querySelector('.grandparent')
			const parent = document.querySelector('.parent')
			const child = document.querySelector('.child')

			// closest() 方法获取 child 的指定父元素
			const zj = child.closest('.grandparent')
			console.log(zj)

			// contains() 方法判断 child 是否包含在 grandparent 中
			const isHas = grandparent.contains(child)
			console.log(isHas)
		</script>
	</body>
</html>
